package com.feng.controller;

import com.feng.domain.ResponseResult;
import com.feng.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "热门文章")
    @GetMapping("/hotArticle")
    public ResponseResult hotArticle(){
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    @ApiOperation(value = "全部文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页面"),
            @ApiImplicitParam(name = "pageSize", value = "页面数据条数"),
            @ApiImplicitParam(name = "categoryId", value = "分类")
    })
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize, Long categoryId){
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    @ApiOperation(value = "文章详情")
    @ApiImplicitParam(name = "id", value = "文章id")
    @GetMapping("/{id}")
    public ResponseResult articleDetail(@PathVariable("id") Long id){
         return articleService.articleDetail(id);
    }

    @ApiOperation(value = "文章浏览量自增")
    @ApiImplicitParam(name = "id", value = "文章id")
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
